package com.mtl.bookt.service.impl;

import com.mtl.bookt.domain.BookBro;
import com.mtl.bookt.mapper.BookBroMapper;
import com.mtl.bookt.service.IBookBroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.mtl.common.tool.model.Page;

import java.util.List;
/**
 *  服务实现类
 *
 * @author lsc
 * @since 2019-07-03
 */
@Service
public class BookBroServiceImpl implements IBookBroService {

    @Autowired
    private BookBroMapper bookBroMapper;

    @Override
    public BookBro findById(Integer id) {
        return bookBroMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<BookBro> findPage(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<BookBro> bookBros=bookBroMapper.selectAll();
        return new Page<>(bookBros);
    }

    @Override
    public int saveOrUpdate(BookBro bookBro) {
        if(bookBro.getBookId()!=null){
        return bookBroMapper.updateByPrimaryKey(bookBro);
        }
        return bookBroMapper.insert(bookBro);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        return bookBroMapper.deleteByIdList(ids);
    }
}
